<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
	
<%@page import="com.lovo.bbs.vo.*,com.lovo.bbs.bo.*,java.util.*"%>

<%
    //请求页
    String queryPages = (String)request.getParameter("queryPage");
	if(queryPages==null||"".equals(queryPages)||"0".equals(queryPages)){
	  queryPages="1";
	}
	int queryPage=Integer.parseInt(queryPages);
	
    //论坛列表
	ArrayList<ForumVo> forumList = (ArrayList<ForumVo>) application.getAttribute("forumList");
	
	//采集论坛回帖列表(数据库分页)
	String asForumId = request.getParameter("forumSelect");//搜索范围
	if(asForumId==null||"".equals(asForumId)){
	    asForumId="0";//为0时将搜索所有论坛下的回帖
	}
	int forumid = Integer.parseInt(asForumId);
	PostBo postBo = new PostBo();
	ArrayList<PostVo> postList = postBo.getPostByForumID(forumid,queryPage);

	int pageCount = postBo.getPostNumByForumID(forumid);
	int pageNum = (pageCount % 20 == 0) ? (pageCount / 20) : (pageCount / 20 + 1);
	Iterator it, it1;
%>
<html>
	<head>
		<link href="../../../css/admin.css" rel="stylesheet" type="text/css" />
		<script type="text/javascript" src="../../../js/wbs_admin.js"></script>
		<script type="text/javascript">
		function preQuery(){
			document.frmMain.action="postManageQueryPage.jsp";
			document.frmMain.submit();
		}
		
		function preModify(postid,posttopic,username,postdate){
			document.frmMain.postid.value=postid;
			document.frmMain.posttopic.value=posttopic;
			document.frmMain.username.value=username;
			document.frmMain.postdate.value=postdate;

			document.frmMain.opType.value=2;
			document.frmMain.action="postManageUpdatePage.jsp";
			document.frmMain.submit();
		}
		
		function preDelete(postid,posttopic,username,postdate){
			document.frmMain.postid.value=postid;
			document.frmMain.posttopic.value=posttopic;
			document.frmMain.username.value=username;
			document.frmMain.postdate.value=postdate;

			document.frmMain.opType.value=3;
			document.frmMain.action="postManageUpdatePage.jsp";
			document.frmMain.submit();
		}
				
		</script>
	</head>
	<body>
	  <form name="frmMain" method="post">
		 <table class="navigation" style="width:98%" align="center">
			<tr>
				<td>
					当前位置: 帖子管理
				</td>
			</tr>
		 </table>
		 <fieldset style="width:98%" align="center">
			<table align="left">
				<tr>
					<td>
						&nbsp;
					</td>
				</tr>
			</table>
			<br>
			<table align="center">
				<tr>
					<td>
						按照论坛查询:
						<select name="forumSelect">
							<option value="0">
								默认
							</option>
							<%	if (forumList == null) {
									forumList = new ArrayList<ForumVo>();
									System.out.println("boardList为空");
								}
								it1 = forumList.iterator();
								  if (it1 != null) {
										while (it1.hasNext()) {
											ForumVo forumData = (ForumVo) (it1.next());
								%>
								<option value="<%=forumData.getForumID()%>">
									<%=forumData.getForumName()%>
								</option>
								<%}}%>
							</select>
						</td>
						<td>
							<input type="button" class="button" value=" 查询 " onclick="preQuery()">
						</td>
					</tr>
					</table>
		</fieldset>
		<table border="0" cellspacing="0" cellpadding="0" width="98%"  align="center">
				<tr>
					<td>
						<table width="100%" border="0" cellspacing="0" cellpadding="4">
							<tr>
								<td id="content_bar">
									<a class="content_total">帖子总数: <%=pageCount%> ,第<%=queryPage%>页 总<%=pageNum%>页 </a>
									<%	for (int i = 1; i <= pageNum; i++) {
											if (i == queryPage) {
									%>
									<a class="content_pasges_c"><%=i%> </a>
									<%} else {%>
									<a class="content_pasges_a" href="postManageQueryPage.jsp?queryPage=<%=i%>"><%=i%> </a>
									<%} }%>
								</td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<td>
						<table border="0" cellspacing="1" cellpadding="4" class="tableborder" style="width:100%; background-color:#CCFFFF; border:#99FFCC 0px solid">
							<tr class="header">
								<td width="20%">
									所在主题(按楼层显示)
								</td>
								<td width="50%">
									内容
								</td>
								<td width="5%">
									发表人
								</td>
								<td width="5%">
									发表时间
								</td>
								
								<td width="15%">
									操作
								</td>
							</tr>
							<%	if (postList == null) {
									postList = new ArrayList();
									System.out.println("帖子数据为空");
								}
								it = postList.iterator();
								if (it != null) {
									while (it.hasNext()) {
										PostVo postData = (PostVo) (it.next());
							%>
							<tr class="row">
								<td valign="top">
									<%=postData.getTopicTitle()%>
								</td>
								<td align="left" valign="top">
									<%=postData.getContent()%>
								</td>
								<td valign="top">
									<%=postData.getUsername()%>
								</td>
								<td valign="top">
									<%=postData.getPostdate()%>
								</td>
								<td>
									<input type="button" value="修改" class="button" onclick="preModify('<%=postData.getPostid()%>','<%=postData.getPosttitle()%>','<%=postData.getUsername()%>','<%=postData.getPostdate()%>')">
									<input type="button" value="删除" class="button"	style="color:#ff0000;" onclick="preDelete('<%=postData.getPostid()%>','<%=postData.getPosttitle()%>','<%=postData.getUsername()%>','<%=postData.getPostdate()%>')">
								</td>
							</tr>
							<%} }%>
						</table>
					</td>
				</tr>
			</table>
			<br>
			
			<input type="hidden" name="postid" value="">
			<input type="hidden" name="posttopic" value="">
			<input type="hidden" name="username" value="">
			<input type="hidden" name="postdate" value="">
			
			<input type="hidden" name="queryPage" value="<%=queryPage%>">
			
			<input type="hidden" name="opType" value="">
			
		</form>
	</body>
</html>
